package com.wanxi.service.impl;

import com.wanxi.dao.StoresDao;
import com.wanxi.model.ResultModel;
import com.wanxi.model.StoresModel;
import com.wanxi.service.StoresService;
import com.wanxi.util.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 杨金乾
 */
@Service
public class StoresServiceImpl implements StoresService {
    @Autowired
    StoresDao storesDao;

    @Override
    public ResultModel enable(StoresModel storesModel) {
        return null;
    }

    @Override
    public ResultModel add(StoresModel storesModel) {
        SnowflakeIdWorker snowflakeIdWorker=new SnowflakeIdWorker(WorkId.WORK_ID);
        storesModel.setId(snowflakeIdWorker.nextId());
        return ResultModel.getResult(storesDao.add(storesModel));
    }

    @Override
    public ResultModel update(StoresModel storesModel) {
        return ResultModel.getResult(storesDao.update(storesModel));
    }

    @Override
    public ResultModel delete(StoresModel storesModel) {
        return ResultModel.getResult(storesDao.delete(storesModel));
    }

    @Override
    public ResultModel findById(StoresModel storesModel) {
        return ResultModel.getResult(storesDao.findById(storesModel));
    }

    @Override
    public ResultModel findAll(StoresModel storesModel) {
        storesModel.setLimit(10);
        storesModel.setPage((storesModel.getPage()-1)*10);
        return ResultModel.getResult(
                storesDao.findAll(storesModel),
                storesDao.count(storesModel));
    }

    @Override
    public ResultModel count(StoresModel storesModel) {
        return ResultModel.getResult(storesDao.count(storesModel));
    }

    @Override
    public ResultModel isShow(StoresModel storesModel) {
        return ResultModel.getResult(storesDao.isShow(storesModel));
    }

    @Override
    public ResultModel isRecommend(StoresModel storesModel) {
        return null;
    }

    @Override
    public ResultModel whereShow(StoresModel storesModel) {
        return null;
    }
}
